package edu.nf.bs.controller;

import edu.nf.bs.util.HttpUtil;
import org.mvc.web.annotation.RequestMapping;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author Miss f
 * @data 2021-06-21-9:09
 */
public class UploadController {
    @RequestMapping("/upload")
    public void uploadPicture(String pictureName, HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
        Part part = request.getPart("uploadfile") ;
        //HFS远程上传地址
        String url = "http://172.16.16.186:8089/uploadPicture/" ;
        //循环Parts集合
        if(part.getSubmittedFileName() != null){
            HttpUtil.upload(url,part.getSubmittedFileName(), part.getInputStream()) ;

            PrintWriter out = response.getWriter() ;

            //向客户端浏览器响应一个JSON格式的字符串
            out.print("{\"msg\":\"ok\"}");

            out.flush();
            out.close();
        }
    }
}
